package org.jeecg.modules.paycenter.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.paycenter.channel.tonglian.TongLianMemberService;
import org.jeecg.modules.paycenter.enums.PayChannelEnum;
import org.jeecg.modules.paycenter.enums.UTypeEnum;
import org.jeecg.modules.wlhy.bill.entity.HyDriverBill;
import org.jeecg.modules.wlhy.bill.service.IHyDriverBillService;
import org.jeecg.modules.wlhy.company.entity.HyCompany;
import org.jeecg.modules.wlhy.company.service.IHyCompanyService;
import org.jeecg.modules.wlhy.customer.entity.HyCustomer;
import org.jeecg.modules.wlhy.hycarrier.entity.HyCarrier;
import org.jeecg.modules.wlhy.hycarrier.service.IHyCarrierService;
import org.jeecg.modules.wlhy.hydriver.entity.HyDriver;
import org.jeecg.modules.wlhy.hydriver.service.IHyDriverService;
import org.jeecg.modules.wlhy.shipping.service.IHyShippingNoteService;
import org.jeecg.modules.wlhy.tlaccount.entity.HyTlAccount;
import org.jeecg.modules.wlhy.tlaccount.entity.HyTlAccountRecord;
import org.jeecg.modules.wlhy.tlaccount.service.IHyTlAccountRecordService;
import org.jeecg.modules.wlhy.tlaccount.service.IHyTlAccountService;
import org.jeecg.modules.wlhy.utils.HyCfgUtil;
import org.jeecg.modules.wlhy.utils.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

/**
 * 通联支付服务
 */
@RestController
@Slf4j
@RequestMapping("/paycenter/tl")
public class TongLianMemberController {

    @Autowired
    private UserUtil userUtil;

    @Autowired
    private TongLianMemberService memberService;

    @Autowired
    private IHyTlAccountService tlAccountService;

    @Autowired
    private IHyTlAccountRecordService hyTlAccountRecordService;

    @Autowired
    private IHyCarrierService carrierService;

    @Autowired
    private IHyDriverService driverService;

    @Autowired
    private IHyShippingNoteService shippingNoteService;

    @Autowired
    private IHyDriverBillService hyDriverBillService;

    @Autowired
    private IHyCompanyService hyCompanyService;

    @Autowired
    private RedisUtil redisUtil;

    //region 平台
    //平台账户
    @GetMapping(value = "/sys/getAcccount")
    public Result<?> getSysAcccount() {
        if(!userUtil.isSys())
        {
            return Result.error("无权限查看");
        }
        HyTlAccount account = tlAccountService.getById("111111");
        if (account == null) {
            return Result.OK();
        }
//        if ("1".equals(account.getIzOpen())) {
//            if (HyCfgUtil.isTongLianUsed()) {
//                memberService.getPersonMemberInfo(account);
//            }
//        }

        BigDecimal totalFee = shippingNoteService.getTotalCostPayShipping(null , PayChannelEnum.TONGLIAN.channelType);
        account.setTotalFee(totalFee);
        //=所有分公司剩余服务费的和
        BigDecimal costServoce = tlAccountService.getCompanyCostService();
        account.setCostService(costServoce);
        BigDecimal totalCostService = shippingNoteService.getTotalCostService(null , PayChannelEnum.TONGLIAN.channelType);
        account.setTotalCostService(totalCostService);

        return Result.OK(account);
    }
    //endregion

    //region 司机
    @GetMapping(value = "/driver/getAcccount")
    public Result<?> getDriverAcccount() {
        HyDriver driver = userUtil.getDriver();
        HyTlAccount account = tlAccountService.getByUid(driver.getId());
        if (account == null) {
            return Result.OK();
        }
        if ("1".equals(account.getIzOpen())) {
            if (HyCfgUtil.isTongLianUsed()) {
                memberService.getPersonMemberInfo(account);
            }
        }
        BigDecimal djsFee = shippingNoteService.getDriverDjsFeeByDriverId(driver.getId());
        account.setDjsFee(djsFee);
        BigDecimal totalFee = shippingNoteService.getDriverTotalFeeByDriverIdAndChannel(driver.getId() , PayChannelEnum.TONGLIAN.channelType);
        account.setTotalFee(totalFee);
        return Result.OK(account);
    }

    @AutoLog(value = "创建司机虚拟子账户")
    @PostMapping(value = "/driver/createAcccount")
    public Result<?> createDriverAcccount() {
        if (!HyCfgUtil.isTongLianUsed()) {
            return Result.error("平台暂未开通服务！");
        }
        HyDriver driver = userUtil.getDriver();
        return memberService.createDriverAcccount(driver, "1");
    }

    @AutoLog(value = "绑定银行卡账户")
    @PostMapping(value = "/driver/applyBindBankCard")
    @Transactional
    public Result<?> applyDriverBindBankCard(@RequestBody JSONObject data) {
        if (!HyCfgUtil.isTongLianUsed()) {
            return Result.error("平台暂未开通服务！");
        }
        String bankid = data.getString("bankid");
        if (StringUtils.isEmpty(bankid)) {
            return Result.error("bankid不能为空");
        }
        HyDriver driver = userUtil.getDriver();
        HyTlAccount account = tlAccountService.getByUidForUpdate(driver.getId());
        if (account == null) {
            return Result.error("未开通钱包");
        }
        if("1" .equals(account.getIzBindBankCard())) {
            return Result.error("已绑定银行卡，不能重复操作");
        }
        return memberService.applyDriverBindBankCard(driver, account, bankid);
    }

    @AutoLog(value = "解绑银行卡账户")
    @PostMapping(value = "/driver/unbindBankCard")
    @Transactional
    public Result<?> unbindDriverBankCard() {
        if (!HyCfgUtil.isTongLianUsed()) {
            return Result.error("平台暂未开通服务！");
        }
        HyDriver driver = userUtil.getDriver();
        HyTlAccount account = tlAccountService.getByUidForUpdate(driver.getId());
        if (account == null) {
            return Result.error("未开通钱包");
        }
        return memberService.unbindBankCard(account, account.getBankCardNo());
    }

    @AutoLog(value = "电子签约")
    @PostMapping(value = "/driver/signContract")
    @Transactional
    public Result<?> signDriverContract(@RequestBody JSONObject data) {
        if (!HyCfgUtil.isTongLianUsed()) {
            return Result.error("平台暂未开通服务！");
        }
        String jumpPageType = data.getString("jumpPageType");
        if (StringUtils.isEmpty(jumpPageType)) {
            return Result.error("jumpPageType不能为空");
        }
        if(!"1".equals(jumpPageType) && !"2".equals(jumpPageType)){
            return Result.error("jumpPageType类型错误");
        }

        HyDriver driver = userUtil.getDriver();
        HyTlAccount account = tlAccountService.getByUidForUpdate(driver.getId());
        if (account == null) {
            return Result.error("未开通钱包");
        }
        if ("1".equals(account.getIzSignContract())) {
            return Result.error("已签约，不能重复操作");
        }
        return memberService.signContract(account,  jumpPageType, "1");
    }

    @GetMapping(value = "/driver/sendVerificationCode")
    public Result<?> sendDriverVerificationCode(@RequestParam(name="phone",required=true) String phone,
                                          @RequestParam(name="verificationCodeType",required=true) String verificationCodeType) {
        if(!HyCfgUtil.isTongLianUsed()){
            return Result.error("平台暂未开通服务！");
        }
        HyDriver driver = userUtil.getDriver();
        HyTlAccount account = tlAccountService.getByUid(driver.getId());
        if (account == null) {
            return Result.error("未开通钱包");
        }
        //验证码类型 9-绑定手机;6-解绑手机
        return memberService.sendVerificationCode(account, phone, verificationCodeType);
    }

    @PostMapping(value = "/driver/bindPhone")
    @Transactional
    public Result<?> bindDriverPhone(@RequestBody JSONObject data) {
        if(!HyCfgUtil.isTongLianUsed()){
            return Result.error("平台暂未开通服务！");
        }
        String verificationCode = data.getString("verificationCode");
        if(StringUtils.isEmpty(verificationCode)){
            return Result.error("验证码不能为空");
        }

        String phone = data.getString("phone");
        if(StringUtils.isEmpty(phone)){
            return Result.error("手机号不能为空");
        }
        HyDriver driver = userUtil.getDriver();
        HyTlAccount account = tlAccountService.getByUidForUpdate(driver.getId());
        if (account == null) {
            return Result.error("未开通钱包");
        }
        if("1" .equals(account.getIzPhoneChecked())) {
            return Result.error("已绑定手机，不能重复操作");
        }
        return memberService.bindPhone(account, phone , verificationCode);
    }

    @PostMapping(value = "/driver/unbindPhone")
    @Transactional
    public Result<?> unbindDriverPhone(@RequestBody JSONObject data) {
        if (!HyCfgUtil.isTongLianUsed()) {
            return Result.error("平台暂未开通服务！");
        }

        String verificationCode = data.getString("verificationCode");
        if (StringUtils.isEmpty(verificationCode)) {
            return Result.error("验证码不能为空");
        }

        HyDriver driver = userUtil.getDriver();
        HyTlAccount account = tlAccountService.getByUidForUpdate(driver.getId());
        if (account == null) {
            return Result.error("未开通钱包");
        }
        return memberService.unbindPhone(account, account.getPhone(), verificationCode);
    }


    @PostMapping(value = "/driver/uploadImg")
    public Result<?> uploadDriverImg() {
        if (!HyCfgUtil.isTongLianUsed()) {
            return Result.error("平台暂未开通服务！");
        }
        HyDriver driver = userUtil.getDriver();
        HyTlAccount account = tlAccountService.getByUid(driver.getId());
        if (account == null) {
            return Result.error("未开通钱包");
        }
        return memberService.uploadDriverImg(driver, account);
    }

    @PostMapping(value = "/driver/uploadImg2")
    public Result<?> uploadDriverImg2() {
        if (!HyCfgUtil.isTongLianUsed()) {
            return Result.error("平台暂未开通服务！");
        }
        HyDriver driver = userUtil.getDriver();
        HyTlAccount account = tlAccountService.getByUid(driver.getId());
        if (account == null) {
            return Result.error("未开通钱包");
        }
        return memberService.uploadDriverImg2(driver, account);
    }

    @PostMapping(value = "/driver/uploadDriverTransportCertificateImg")
    public Result<?> uploadDriverTransportCertificateImg2() {
        if(!HyCfgUtil.isTongLianUsed()){
            return Result.error("平台暂未开通服务！");
        }
        HyDriver driver = userUtil.getDriver();
        HyTlAccount account = tlAccountService.getByUid(driver.getId());
        if (account == null) {
            return Result.error("未开通钱包");
        }
        return memberService.uploadDriverTransportCertificateImg(account);
    }

    @GetMapping(value = "/driver/bill/list")
    public Result<?> driverBillList(HyDriverBill hyDriverBill,
                                    @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                    @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                    HttpServletRequest req) {
        HyDriver driver = userUtil.getDriver();
        QueryWrapper<HyDriverBill> queryWrapper = QueryGenerator.initQueryWrapper(hyDriverBill, req.getParameterMap());
        queryWrapper.eq("driver_id", driver.getId())
                .eq("resp_source", "0").eq("pay_channel", PayChannelEnum.TONGLIAN.channelType).ne("bill_type", "3").orderByDesc("create_time");

        String year = req.getParameter("year");
        if (StringUtils.isNotBlank(year)) {
            String month = req.getParameter("month");
            if (StringUtils.isBlank(month)) {
                queryWrapper.apply("YEAR(create_time)={0}", year);
            } else {
                queryWrapper.apply("DATE_FORMAT(create_time,'%Y-%m')={0}", year + "-" + month);
            }
        }

        Page<HyDriverBill> page = new Page<HyDriverBill>(pageNo, pageSize);
        IPage<HyDriverBill> pageList = hyDriverBillService.page(page, queryWrapper);
        return Result.OK(pageList);
    }
    //endregion

    //region 货主
    @GetMapping(value = "/customer/getAcccount")
    public Result<?> getCustomerAcccount() {
        HyCustomer customer = userUtil.getCustomer();
        HyTlAccount account = tlAccountService.getByUid(customer.getId());
        if (account == null) {
            return Result.OK();
        }
        if ("1".equals(account.getIzOpen())) {
            if (HyCfgUtil.isTongLianUsed()) {
                memberService.getPersonMemberInfo(account);
            }
        }
        BigDecimal djsFee = shippingNoteService.getCustomerDjsFee(customer.getId());
        account.setDjsFee(djsFee);
        BigDecimal totalFee = shippingNoteService.getCustomerTotalFeeByChannel(customer.getId() , PayChannelEnum.TONGLIAN.channelType);
        account.setTotalFee(totalFee);
        return Result.OK(account);
    }

    @AutoLog(value = "创建货主钱包")
    @PostMapping(value = "/customer/createAcccount")
    public Result<?> createCustomerAcccount(@RequestBody JSONObject data) throws Exception {
        if(!HyCfgUtil.isTongLianUsed()){
            return Result.error("平台暂未开通服务！");
        }
        HyCustomer customer = userUtil.getCustomer();
        return memberService.createCustomerAccount(customer , data);
    }

    @AutoLog(value = "货主充值")
    @PostMapping(value = "/customer/recharge")
    public Result<?> customerRecharge(@RequestBody JSONObject data) throws Exception {
        if(!HyCfgUtil.isTongLianUsed()){
            return Result.error("平台暂未开通服务！");
        }
        HyCustomer customer = userUtil.getCustomer();
        data.put("source","2");
        return memberService.customerRecharge(customer , data);
    }

    @GetMapping(value = "/customer/rerecharge")
    public Result<?> customerReRecharge(@RequestParam(name="id") String id){
        if(StringUtils.isEmpty(id)){
            return Result.error("id不能为空");
        }
        if(!HyCfgUtil.isTongLianUsed()){
            return Result.error("平台暂未开通服务！");
        }
        HyTlAccountRecord record = hyTlAccountRecordService.getById(id);
        if(record == null){
            return Result.error("记录不存在");
        }
        if(!"1".equals(record.getOptType())){
            return Result.error("订单类型错误");
        }
        if ("1".equals(record.getSt())) {
            return Result.error("该订单已支付完成，不能重复支付");
        }
        if ("2".equals(record.getSt())) {
            return Result.error("该订单支付失败，请重新发起支付");
        }
        if(!userUtil.isSys()){
            HyCustomer customer = userUtil.getCustomer();
            if(!StringUtils.equals(customer.getId(),record.getUid())){
                return Result.error("数据错误");
            }
        }
        String merOrderNo = record.getMerOrderNo();
        String payStatus = memberService.getOrderPayStatus(merOrderNo);
        if ("0".equals(payStatus)) {
            String rediskey = "merOrderNo:" + merOrderNo;
            if (!redisUtil.hasKey(rediskey)) {
                record.setSt("4");
                hyTlAccountRecordService.updateById(record);
                return Result.error(-2, "该订单已过期，请重新发起支付");
            }
            String payInfo = redisUtil.get(rediskey).toString();
            return Result.OK(payInfo);
        }else if ("1".equals(payStatus)) {
            return Result.error(-2, "该订单已支付完成，不能重复支付");
        } else if ("2".equals(payStatus)) {
            return Result.error(-2, "该订单支付失败，请重新发起支付");
        } else {
            return Result.error(-2, "该订单支付失败，请重新发起支付");
        }
    }

    @AutoLog(value = "创建账户")
    @PostMapping(value = "/carrier/createAcccount")
    public Result<?> createCarrierAcccount(@RequestBody JSONObject data)  {
//        if(!HyCfgUtil.isTongLianUsed()){
//            return Result.error("平台暂未开通服务！");
//        }
//        String uid = data.getString("uid");
//        if(StringUtils.isEmpty(uid)){
//            return Result.error("uid不能为空");
//        }
//        HyCarrier carrier = carrierService.getById(uid);
//        if(carrier == null){
//            return Result.error("车队长信息不存在");
//        }
//        HyCustomer customer = userUtil.getCustomer();
//        if(!StringUtils.equals(customer.getId(), carrier.getCustomerId())){
//            return Result.error("车队长信息错误");
//        }
//        return memberService.createCarrierAccount(carrier , data);
        return Result.error("todo");
    }
    //endregion

    //region base
    @GetMapping(value = "/getByUId")
    public Result<?> getByUId(@RequestParam(name="uid",required=true) String uid) {
        HyTlAccount account = tlAccountService.getByUid(uid);
        if (account == null) {
            return Result.OK();
        }
        if ("1".equals(account.getIzOpen())) {
            if (HyCfgUtil.isTongLianUsed()) {
                memberService.getPersonMemberInfo(account);
            }
        }
        if (UTypeEnum.DRIVER.uType.equals(account.getUtype())) {
            BigDecimal djsFee = shippingNoteService.getDriverDjsFeeByDriverId(uid);
            account.setDjsFee(djsFee);
            BigDecimal totalFee = shippingNoteService.getDriverTotalFeeByDriverIdAndChannel(uid, PayChannelEnum.TONGLIAN.channelType);
            account.setTotalFee(totalFee);
        } else if (UTypeEnum.COMPANY.uType.equals(account.getUtype())) {
            BigDecimal totalFee = shippingNoteService.getTotalCostPayShipping(uid, PayChannelEnum.TONGLIAN.channelType);
            account.setTotalFee(totalFee);
            BigDecimal totalCostService = shippingNoteService.getTotalCostService(uid, PayChannelEnum.TONGLIAN.channelType);
            account.setTotalCostService(totalCostService);
        }
        return Result.OK(account);
    }

    @AutoLog(value = "创建账户")
    @PostMapping(value = "/createAcccount")
    public Result<?> createAcccount(@RequestBody JSONObject data) {
        if (!HyCfgUtil.isTongLianUsed()) {
            return Result.error("平台暂未开通服务！");
        }
        String uid = data.getString("uid");
        if (StringUtils.isEmpty(uid)) {
            return Result.error("uid不能为空");
        }
        String utype = data.getString("utype");
        if (StringUtils.isEmpty(utype)) {
            return Result.error("utype不能为空");
        }
        UTypeEnum uTypeEnum = UTypeEnum.getUTypeEnum(utype);
        switch (uTypeEnum) {
            case DRIVER: {
                HyDriver driver = driverService.getById(uid);
                if (driver == null) {
                    return Result.error("司机信息不存在");
                }
                return memberService.createDriverAcccount(driver, "2");
            }
            case CARRIER: {
                HyCarrier carrier = carrierService.getById(uid);
                if (carrier == null) {
                    return Result.error("车队长信息不存在");
                }
                return memberService.createCarrierAccount(carrier, "2");
            }
            case COMPANY: {
                HyCompany company = hyCompanyService.getById(uid);
                if (company == null) {
                    return Result.error("分公司信息不存在");
                }
                return memberService.createCompanyAccount(company, "2");
            }
            default:
                return Result.error("用户类型错误");
        }
    }

    @AutoLog(value = "绑定银行卡账户")
    @PostMapping(value = "/applyBindBankCard")
    @Transactional
    public Result<?> applyBindBankCard(@RequestBody JSONObject data) {
        if (!HyCfgUtil.isTongLianUsed()) {
            return Result.error("平台暂未开通服务！");
        }
        String uid = data.getString("uid");
        if (StringUtils.isEmpty(uid)) {
            return Result.error("uid不能为空");
        }

        HyTlAccount account = tlAccountService.getByUidForUpdate(uid);
        if (account == null) {
            return Result.error("未开通钱包");
        }

        UTypeEnum uTypeEnum = UTypeEnum.getUTypeEnum(account.getUtype());
        switch (uTypeEnum) {
            case DRIVER: {
                HyDriver driver = driverService.getById(uid);
                if (driver == null) {
                    return Result.error("司机信息不存在");
                }
                String bankid = data.getString("bankid");
                if (StringUtils.isEmpty(bankid)) {
                    return Result.error("bankid不能为空");
                }
                return memberService.applyDriverBindBankCard(driver, account, bankid);
            }
            case CARRIER:
                HyCarrier carrier = carrierService.getById(uid);
                if (carrier == null) {
                    return Result.error("车队长信息不存在");
                }
                return memberService.applyCarrierBindBankCard(carrier, account);
            default:
                return Result.error("用户类型错误");
        }
    }

    @AutoLog(value = "解绑银行卡账户")
    @PostMapping(value = "/unbindBankCard")
    @Transactional
    public Result<?> unbindBankCard(@RequestBody JSONObject data) {
        if (!HyCfgUtil.isTongLianUsed()) {
            return Result.error("平台暂未开通服务！");
        }
        String uid = data.getString("uid");
        if (StringUtils.isEmpty(uid)) {
            return Result.error("uid不能为空");
        }

        String bankCardNo = data.getString("bankCardNo");
        if (StringUtils.isEmpty(bankCardNo)) {
            return Result.error("bankCardNo不能为空");
        }

        HyTlAccount account = tlAccountService.getByUidForUpdate(uid);
        if (account == null) {
            return Result.error("未开通钱包");
        }
        return memberService.unbindBankCard(account, bankCardNo);
    }

    @AutoLog(value = "电子签约")
    @PostMapping(value = "/signContract")
    public Result<?> signContract(@RequestBody JSONObject data) {
        if (!HyCfgUtil.isTongLianUsed()) {
            return Result.error("平台暂未开通服务！");
        }
        String uid = data.getString("uid");
        if (StringUtils.isEmpty(uid)) {
            return Result.error("uid不能为空");
        }

        HyTlAccount account = tlAccountService.getByUid(uid);
        if (account == null) {
            return Result.error("未开通钱包");
        }
        return memberService.signContract(account, "1", "2");
    }

    @GetMapping(value = "/sendVerificationCode")
    public Result<?> sendVerificationCode(@RequestParam(name="uid",required=true) String uid,
                              @RequestParam(name="phone",required=true) String phone,
                              @RequestParam(name="verificationCodeType",required=true) String verificationCodeType) {
        if(!HyCfgUtil.isTongLianUsed()){
            return Result.error("平台暂未开通服务！");
        }
        HyTlAccount account = tlAccountService.getByUid(uid);
        if (account == null) {
            return Result.error("未开通钱包");
        }
        //验证码类型 9-绑定手机;6-解绑手机
        return memberService.sendVerificationCode(account, phone, verificationCodeType);
    }

    @PostMapping(value = "/bindPhone")
    @Transactional
    public Result<?> bindPhone(@RequestBody JSONObject data) {
        if(!HyCfgUtil.isTongLianUsed()){
            return Result.error("平台暂未开通服务！");
        }
        String uid = data.getString("uid");
        if(StringUtils.isEmpty(uid)){
            return Result.error("uid不能为空");
        }
        String verificationCode = data.getString("verificationCode");
        if(StringUtils.isEmpty(verificationCode)){
            return Result.error("验证码不能为空");
        }

        String phone = data.getString("phone");
        if(StringUtils.isEmpty(phone)){
            return Result.error("手机号不能为空");
        }

        HyTlAccount account = tlAccountService.getByUidForUpdate(uid);
        if (account == null) {
            return Result.error("未开通钱包");
        }
        return memberService.bindPhone(account, phone , verificationCode);
    }

    @PostMapping(value = "/unbindPhone")
    public Result<?> unbindPhone(@RequestBody JSONObject data) {
        if(!HyCfgUtil.isTongLianUsed()){
            return Result.error("平台暂未开通服务！");
        }
        String uid = data.getString("uid");
        if(StringUtils.isEmpty(uid)){
            return Result.error("uid不能为空");
        }
        String verificationCode = data.getString("verificationCode");
        if(StringUtils.isEmpty(verificationCode)){
            return Result.error("验证码不能为空");
        }

        String phone = data.getString("phone");
        if(StringUtils.isEmpty(phone)){
            return Result.error("手机号不能为空");
        }

        HyTlAccount account = tlAccountService.getByUid(uid);
        if (account == null) {
            return Result.error("未开通钱包");
        }
        return memberService.unbindPhone(account, phone , verificationCode);
    }


    @PostMapping(value = "/uploadImg")
    public Result<?> uploadImg(@RequestBody JSONObject data) {
        if(!HyCfgUtil.isTongLianUsed()){
            return Result.error("平台暂未开通服务！");
        }
        String uid = data.getString("uid");
        if(StringUtils.isEmpty(uid)){
            return Result.error("uid不能为空");
        }

        HyTlAccount account = tlAccountService.getByUid(uid);
        if (account == null) {
            return Result.error("未开通钱包");
        }

        UTypeEnum uTypeEnum = UTypeEnum.getUTypeEnum(account.getUtype());
        switch (uTypeEnum){
            case DRIVER:
                HyDriver driver = driverService.getById(uid);
                if(driver == null){
                    return Result.error("司机信息不存在");
                }
                return memberService.uploadDriverImg(driver , account);
            case CARRIER:
                HyCarrier carrier = carrierService.getById(uid);
                if(carrier == null){
                    return Result.error("车队长信息不存在");
                }
                return memberService.uploadCarrierImg(account, carrier);
            default:
                return Result.error("用户类型错误");
        }
    }

    @PostMapping(value = "/uploadImg2")
    public Result<?> uploadImg2(@RequestBody JSONObject data) {
        if (!HyCfgUtil.isTongLianUsed()) {
            return Result.error("平台暂未开通服务！");
        }
        String uid = data.getString("uid");
        if (StringUtils.isEmpty(uid)) {
            return Result.error("uid不能为空");
        }

        HyTlAccount account = tlAccountService.getByUid(uid);
        if (account == null) {
            return Result.error("未开通钱包");
        }

        UTypeEnum uTypeEnum = UTypeEnum.getUTypeEnum(account.getUtype());
        switch (uTypeEnum) {
            case DRIVER:
                HyDriver driver = driverService.getById(uid);
                if (driver == null) {
                    return Result.error("司机信息不存在");
                }
                return memberService.uploadDriverImg2(driver, account);
            default:
                return Result.error("用户类型错误");
        }
    }

    @PostMapping(value = "/uploadDriverTransportCertificateImg")
    public Result<?> uploadDriverTransportCertificateImg(@RequestBody JSONObject data) {
        if(!HyCfgUtil.isTongLianUsed()){
            return Result.error("平台暂未开通服务！");
        }
        String uid = data.getString("uid");
        if(StringUtils.isEmpty(uid)){
            return Result.error("uid不能为空");
        }

        HyTlAccount account = tlAccountService.getByUid(uid);
        if (account == null) {
            return Result.error("未开通钱包");
        }

        UTypeEnum uTypeEnum = UTypeEnum.getUTypeEnum(account.getUtype());
        switch (uTypeEnum){
            case DRIVER:
                return memberService.uploadDriverTransportCertificateImg(account);
            default:
                return Result.error("用户类型错误");
        }
    }
    //endregion

}
